package v1

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
	"superTools-backend/pkg/app"
	"superTools-backend/pkg/e"
	"superTools-backend/pkg/logging"
	"superTools-backend/tools"
)

/**
* @Author: super
* @Date: 2020-08-21 21:50
* @Description:
**/

// @Summary 根据传递的字符串生成二维码
// @Produce  json
// @Param str query string true "要生成对应二维码的地址"
// @success 200 {string} string "{"code":200,"data":{},"msg":"ok"}"
// @Router /api/v1/qrcode [get]
func GetQRcode(c *gin.Context) {
	appG := app.Gin{C:c}
	str := c.Query("str")

	bytes, err := tools.GenerateQRCodeByte(str)

	if err != nil {
		logging.GetLogger().Error("generate qr-code", zap.Error(err))
		appG.Response(http.StatusOK, e.INVALID_PARAMS, "")
		return
	}

	encode := tools.Base64Encode(bytes)

	appG.Response(http.StatusOK, e.SUCCESS, encode)
}
